package Classroom2;

import java.lang.reflect.Field;

public class Test2 {
    public static void main(String[] args) throws Exception {
        //通过反射获取字段对象
        Class clazz = Class.forName("Classroom2.Student");
        Object o = clazz.newInstance();
        Field age = clazz.getDeclaredField("age");
        age.setAccessible(true);
        age.set(o,18);
        System.out.println(o);
    }
}
